<template>
  <div class="butt-list-sty">
    <div class="butt-list-sty-wrap">
      <div
        v-for="(item, index) in topitemSelectList"
        :key="item.equipmentTypeCode"
        :class="index === itemtypeactive ? 'basebut1' : 'basebut2'"
        @click="itemtypeactive = index"
      >{{ item.equipmentTypeName }}</div>
    </div>
  </div>
</template>

<script>
import equipTypeApi from "@/api/equip-manage/equip-type/index";

export default {
  data() {
    return {
      itemtypeactive: 0,
      topitemSelectList: [],
    };
  },
  watch: {
    itemtypeactive(newvalue) {
      this.selbut(newvalue);
    },
  },
  created() {
    this.queryParentList();
  },
  mounted() {},
  methods: {
    selbut(i) {
      this.$emit("topitemtype", this.topitemSelectList[i]["equipmentTypeCode"]);
    },
    // 查询最父级的类型
    queryParentList() {
      this.loading = true;
      // 查询表格
      equipTypeApi.queryTopAll().then((res) => {
        this.loading = false;
        // 赋值数组
        if (res.code === 1) {
          let data = res.data || [];
          this.topitemSelectList = [];
          for (var i in data) {
            this.topitemSelectList.push({
              equipmentTypeName: data[i],
              equipmentTypeCode: i,
            });
          }
          if (this.topitemSelectList.length > 0) {
            this.selbut(0);
          }
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "~@/styles/variables.scss";
.butt-list-sty {
  width: 100%;
  padding: 0 20px;
  overflow: hidden;
  background: $hamburgerBgColor;
}
.butt-list-sty-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
}
.basebut1 {
  height: 36px;
  line-height: 36px;
  font-size: 17px;
  text-align: center;
  background-image: linear-gradient(#0fa1d2, #1087af, #106f8f);
  border: #f6f9f9 1px solid;
  border-radius: 19px;
  color: #ffffff;
  cursor: pointer;
  margin: 3px 5px;
  padding: 0 40px;
  white-space: nowrap;
  // transform: translateY(50%);
}
.basebut2 {
  // width: 120px;
  height: 35px;
  line-height: 35px;
  font-size: 17px;
  text-align: center;
  background-color: #106986;
  border-radius: 19px;
  color: #ffffff;
  cursor: pointer;
  margin: 3px 5px;
  padding: 0 40px;
  white-space: nowrap;
  // transform: translateY(50%);
}
</style>
